# This is a sample Python script.

# Press Shift+F10 to execute it or replace it with your code.
# Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings.

import sys
from PyQt5.QtWidgets import QApplication, QWidget, QMessageBox
from main_ui import Ui_Form
from checkdata import CheckData


class Analysis(QWidget, Ui_Form):
    def __init__(self):
        super().__init__()
        self.setupUi(self)
        self.textEdit.clear()

    def startAnalysis(self):
        if len(self.textEdit.toPlainText()) == 0:
            QMessageBox.information(self, "提示", "没有需要分析的文件")
            return
        for _file in self.textEdit.toPlainText().split('\n'):
            if len(_file) == 0:
                continue
            c = CheckData(_file)
            if self.lineEditSortLevel.text() != '':
                c.set_sort_level(int(self.lineEditSortLevel.text()))
            _key, _value = c.read_file()
            if _key != 0:
                QMessageBox.information(self, "错误", "文件格式错误，存在未知列,请检查！\n错误信息:{}".format(_value))
                return
            k, v = c.check()
            if k != 0:
                QMessageBox.information(self, "错误", "文件:{}\n错误信息:{}".format(_file, v))
                return
        QMessageBox.information(self, "提示", "分析完成，请打开生成的文件检查结果")
        self.textEdit.clear()


if __name__ == '__main__':
    app = QApplication(sys.argv)
    a = Analysis()
    a.show()
    sys.exit(app.exec_())
